package com.lxl.hadoop.order;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

/**
 * @Author lixilin
 * @Date 2022/1/1 12:06
 * @Description
 * 分组排序, 在进入reduce前进行分组排序
 */
public class OrderGroupingComparator extends WritableComparator {
    protected OrderGroupingComparator() {
        super(OrderBean.class,true);
    }

    @Override
    public int compare(WritableComparable a, WritableComparable b) {

        // 只要订单号一样,就认为是相同的key
        OrderBean aOrder =(OrderBean)a;
        OrderBean bOrder =(OrderBean)b;
        Integer aCode = aOrder.getOrderCode();
        Integer bCode = bOrder.getOrderCode();
        if (aCode == bCode) {
            return 0;
        }
        if (aCode > bCode) {
            return 1;
        }
        return -1;
    }
}
